﻿namespace OWA2SMTP
{
  class MessageSender
  {
    public string mailServer { get; private set; }
    public string from { get; private set; }
    public string to { get; private set; }

    public MessageSender(string mailServer, string from, string to)
    {
      this.mailServer = mailServer;
      this.from = from;
      this.to = to;
      Program.ShowMessage("   Sending e-mails using server \"{0}\" from \"{1}\" to \"{2}\"", mailServer, from, to);
    }

    public void SendEmail(string subject, string body)
    {
      Program.ShowMessage("      Sending e-mail with subject \"{0}\"", subject);
      System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
      message.To.Add(to);
      message.Subject = subject;
      message.From = new System.Net.Mail.MailAddress(from);
      message.Body = body;
      System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient(mailServer);
      smtp.Send(message);
    }
  }
}